# -*- coding: utf-8 -*-

import time
from . import JiangHu

# 辅助
class Sup(JiangHu.JiangHu):
    def __init__(self, thread_id, name, index, public_data,ignore_block):
        super().__init__(thread_id, name, index, public_data,ignore_block)
        self.log.info("xxxxx2")

    def first_init(self):
        self.publicData["游戏线程大漠插件是否绑定"] = 0
        self.publicData["人物不在黄陵次数"] = 0
        if self.publicData["系统"]["次要阶段"] == 0 or self.publicData["系统"]["次要阶段"] == "":
            self.publicData["系统"]["次要阶段"] = 1
        self.data["是否在高昌"] =False
        self.data["高昌"] = {
            "1": False,
            "2": False,
            "3": False,
            "4": False,
            "5": False,
            "6": False,
        }
        self.data["是否进船坞扶桑"]=False
        self.data["是否进入论剑"] = False
        self.data["是否论剑中"] = False
        self.data["是否进入黄陵"] = False
        self.data["是否黄陵中"] = False
        self.data["是否商人购买"] = False
        self.data["是否进入龙"] = False
        self.data["任务"] = {
            "6":[r"书\6上采燕功.bmp",r"书\6上蜀道难牌法.bmp",r"书\6上心意气混元功.bmp",r"书\6红三光奇功.bmp"],
            "7":[r"书\7上地火功.bmp",r"书\7上袈裟伏魔功.bmp",r"书\7上金雁功.bmp",r"书\7上控鹤功.bmp",r"书\7上释迦掷象功.bmp",r"书\7红七煞断脉封穴法.bmp",],
            "9":[r"书\9上大力鹰抓功.bmp",r"书\9上闭穴功.bmp",r"书\9上泥鳅功.bmp",r"书\9红圣心诀.bmp"],
            "6全":[
                r"书\6上采燕功.bmp",r"书\6上蜀道难牌法.bmp",r"书\6上心意气混元功.bmp",
                r"书\6中采燕功.bmp",r"书\6中蜀道难牌法.bmp",r"书\6中心意气混元功.bmp",
                r"书\6下采燕功.bmp",r"书\6下蜀道难牌法.bmp",r"书\6下心意气混元功.bmp",],
            "7全":[
                r"书\7上地火功.bmp",r"书\7上袈裟伏魔功.bmp",r"书\7上金雁功.bmp",r"书\7上控鹤功.bmp",r"书\7上释迦掷象功.bmp",
                r"书\7中地火功.bmp",r"书\7中袈裟伏魔功.bmp",r"书\7中金雁功.bmp",r"书\7中控鹤功.bmp",r"书\7中释迦掷象功.bmp",
                r"书\7下地火功.bmp",r"书\7下袈裟伏魔功.bmp",r"书\7下金雁功.bmp",r"书\7下控鹤功.bmp",r"书\7下释迦掷象功.bmp",],
            "9全":[
                r"书\9上大力鹰抓功.bmp",r"书\9上闭穴功.bmp",r"书\9上泥鳅功.bmp",
                r"书\9中大力鹰抓功.bmp",r"书\9中闭穴功.bmp",r"书\9中泥鳅功.bmp",
                r"书\9下大力鹰抓功.bmp",r"书\9下闭穴功.bmp",r"书\9下泥鳅功.bmp",],
            "6上":[
                r"书\6上采燕功.bmp",r"书\6上蜀道难牌法.bmp",r"书\6上心意气混元功.bmp",],
            "7上":[
                r"书\7上地火功.bmp",r"书\7上袈裟伏魔功.bmp",r"书\7上金雁功.bmp",r"书\7上控鹤功.bmp",r"书\7上释迦掷象功.bmp",],
            "9上":[
                r"书\9上大力鹰抓功.bmp",r"书\9上闭穴功.bmp",r"书\9上泥鳅功.bmp",],
            "6上品开启": False,
            "7上品开启": False,
            "9上品开启": False,

        }
        self.data["是否在高昌"] = False
        self.data["是否开启9上"] = False
        self.data["当前任务"] = "0"


    def Process(self):
        self.MoveSafe()
        self.log.info("当前阶段 %s" % self.publicData["系统"]["主要阶段"])
        if "" == self.publicData["系统"]["主要阶段"]:

            res = self.dm.SearchPngClick(810, 425, 1245, 655, "dota2\离开比赛.bmp|dota2\离开比赛2.bmp", 0.8, 1, 1,
                                         1, 10, 10)
            if res == 1:
                self.log.info("重新启动后 点击上把离开比赛")
            self.retryInRoomList()
            self.modifyStage(main_stage="查找房间")

        self.log.info("当前阶段 %s" % self.publicData["系统"]["主要阶段"])
        main_stage = self.publicData["系统"]["主要阶段"]
        # todo 需要封装
        if main_stage == "查找房间":
            is_get = self.dm.SearchPngClick(810, 425, 1245, 655, "dota2\离开比赛.bmp|dota2\离开比赛2.bmp", 0.8, 1,
                                            1, 1, 10, 10)
            if is_get == 1:
                self.log.info("结束上一把比赛 离开游戏")
            is_get1 = self.dm.SearchPngClick(1030, 50, 1100, 720, "dota2\房间.bmp", 0.8, 1, 0.01, 0, 0, 0)
            is_get2 = self.dm.SearchPngClick(500, 325, 750, 375, "dota2\接受开始.bmp", 0.8, 1, 0.5, 0, 0, 0)
            if is_get1 == 1 or is_get2 == 1:
                self.modifyStage(main_stage="进入房间")
            else:
                self.dm.LeftClick(1097, 118, 1)
                for i in range(10):
                    is_get = self.dm.SearchPngClick(50, 125, 350, 175, "dota2\房间前感叹号.bmp", 0.9, 1, 1, 2, 300, 3)
                    if is_get == 1:
                        return
                    else:
                        self.log.info("点击刷新按钮")
                        self.dm.LeftClick(1097, 118, 1)
                is_get = self.dm.SearchPngClick(176, 544, 229, 567, r"dota2\309.bmp", 0.8, 3, 0.5, 0, 0, 0)
                if is_get == 0 and self.publicData["系统"]["主要阶段"]=="查找房间":
                    self.log.info("fafaf")
                    self.retryInRoomList()
        elif main_stage == "进入房间":
            is_get = self.dm.SearchPngClick(500, 325, 750, 375, "dota2\接受开始.bmp|dota2\接受开始2.bmp", 0.8, 1,
                                            0.5,
                                            1,
                                            100, 15)
            if is_get == 1:
                self.publicData["系统数据"]["总局数"] += 1
                # 点击接受后有时不生效
                is_get = self.dm.SearchPngClick(500, 325, 750, 375, "dota2\接受开始.bmp|dota2\接受开始2.bmp", 0.8,
                                                5, 3,
                                                1, 100, 15)
                if is_get == 1:
                    self.dm.SearchPngClick(500, 325, 750, 375, "dota2\接受开始.bmp|dota2\接受开始2.bmp", 0.8, 5, 3,
                                           1,
                                           100, 15)
                self.modifyStage(main_stage="加载游戏")
        elif main_stage == "加载游戏":
            self.modifyStage(second_stage=1)
            if self.data["开始跑马时间"] < 150.0:
                is_get1 = self.dm.WaitPngDisappear(590, 510, 700, 600, "存档\拼命加载中.bmp", 0.8, 1, 0)
                is_get2 = self.dm.WaitPngDisappear(0, 0, 30, 30, "存档\跑马左上角返回.bmp", 0.8, 1, 0)
                if is_get1 == 1 and is_get2 == 1:
                    self.data["开始跑马时间"] = time.time()
            if time.time() - self.data["开始跑马时间"] > self.publicData["系统"]["跑马超时时间"] and self.data["开始跑马时间"] > 150.0:
                self.log.info("启动跑马重连机制")
                self.dm.LeftClick(16, 16, 1)
                self.data["开始跑马时间"] = 0.0
                # 可能会有多余的断开链接弹窗
                is_get = self.dm.SearchPngClick(450, 250, 900, 500,
                                                "dota2\已断开服务器连接.bmp|dota2\已断开服务器连接1.bmp|dota2\已断开服务器连接2.bmp|dota2\已断开服务器连接3.bmp|dota2\已断开服务器连接4.bmp|dota2\已断开服务器连接5.bmp",
                                                0.8, 1, 0, 1, 120, 90)
                if is_get == 1:
                    time.sleep(1)
                self.dm.SearchPngClick(1010, 625, 1245, 655, "dota2\断开连接.bmp|dota2\断开连接2.bmp", 0.8, 10, 0,
                                       1, 10, 10, is_wait=1)
                return  0

            is_get = self.dm.SearchPngClick(1000, 625, 1250, 700, "开始游戏.bmp", 0.8, 5, 0.5, 0, 0, 0, is_wait=1)

            if is_get == 1 :
                self.modifyStage(main_stage="人物选择")
                self.log.info("混子人物选择")
            is_get2 = self.dm.SearchPngClick(500, 1, 650, 35, "存档\选难度界面倒计时框框.bmp", 0.95, 1, 0.5, 0, 0, 0)
            if is_get2==1:
                self.data["开始跑马时间"] = 0.0

        elif main_stage == "人物选择":
            self.ChooseSect()
        elif main_stage == "分解":
            self.publicData["系统数据"]["进入游戏数"] += 1
            self.data["本局开始时间"] = time.time()

            is_get = self.dm.SearchPngClick(125, 650, 165, 675, "f4.bmp", 0.8, 1500, 0.1, 0, 0, 0)
            if is_get == 1:
                # 卡会心
                self.StuckBug1()
            self.GoSect()
            time.sleep(3)
            self.log.info("开始保存大哥头像")
            dm_ret = self.dm.Capture(42, 50, 49, 57, "dage.bmp")
            self.log.info("保存大哥头像结束 结果 %s" % dm_ret)
            time.sleep(1)
            self.SwitchQSkill(self.publicData["通用"]["落地切换q"])
            if self.publicData["通用"]["自动释放q"]:
                time.sleep(1)
                self.AutoQ()
            self.log.info("开始分解装备 吃静脉奇石")
            self.EquipArms()

            if self.publicData["通用"]["自动释放q"]:
                self.AutoQ()
            if self.publicData["每日"]["是否轮回狂风快刀"]:
                if self.index % self.publicData["每日"]["轮回狂风间隔"] == 0:
                    self.Reincarnation()
            if self.publicData["每日"]["金锭"]:
                self.CollectGoldIngots()
            self.EatStone()
            self.modifyStage(main_stage="发育")
        elif main_stage == "发育":
            self.DaHuanDdan()
            if self.publicData["辅助"]["是否抽宝石"]:
                self.SupDrawGem()
                self.SupExchangeMilitaryAchievements(8)
            else:
                self.SupExchangeMilitaryAchievements(6)
            self.dm.KeyPressChar("f1",num=2)
            if self.publicData["辅助"]["R紫"]:
                self.RGemPurple()
            second_stage = self.get_second_stage()
            self.log.info(second_stage)
            if second_stage == 1:
                self.GoSect()
                time.sleep(1)
                if self.data["玩家楼层"] == 0:
                    self.CheckFloor()
                    self.log.info(self.data["玩家楼层"])
                self.log.info(self.data["玩家楼层"])
                self.ExchangeMilitaryAchievements(5)
                self.ExchangeMilitaryAchievements(5)
                self.AccessHomeNPC("战功兑换")
                res=self.AccessCarryNPC("小师妹")
                if res == 1:
                    self.modifyStage(second_stage=second_stage + 1)
            elif second_stage == 2:
                # 推主线
                res = self.CompleteMainTask1(7, 20)
                if res > 7:
                    self.modifyStage(second_stage=second_stage + 1)
            elif second_stage == 3:
                is_get = self.AccessNPC(61, 662, 700, 315)
                if is_get !=1:
                    is_get = self.AccessNPC(61, 662, 700, 315)
                path=r"NPC选项\马啸西风.bmp"
                self.dm.WaitPngDisappear(447, 619, 925, 714, path, 0.9, 10, 0.102, 2, 10, 10, is_wait=1)
                path = r"NPC选项\八级宝石解封.bmp"
                self.dm.WaitPngDisappear(447, 619, 925, 714, path, 0.9, 10, 0.102, 2, 10, 10, is_wait=1)

                path = r"NPC选项\马啸西风_已选择.bmp"
                is_get1=self.dm.WaitPngDisappear(447, 619, 925, 714, path, 0.9, 10, 0.102, 0, 0, 0)
                path = r"NPC选项\八级宝石解封_已选择.bmp"
                is_get2=self.dm.WaitPngDisappear(447, 619, 925, 714, path, 0.9, 10, 0.102, 0, 0, 0)
                if is_get1 == 1 and is_get2==1 :
                    self.modifyStage(second_stage=second_stage + 1)
                else:
                    # todo
                    self.modifyStage(second_stage=second_stage + 1)

            elif second_stage == 4:
                # 等待兑换完客昌丹和功法残页
                res = self.ExchangeMilitaryAchievements(5)
                if res == 1:
                    self.modifyStage(second_stage=second_stage + 1)
            elif second_stage ==5 :
                # 高昌打钱
                self.log.info(self.data["是否在高昌"])
                self.log.info(self.data)
                self.JoinGaoChangCheck(1)
                if self.data["高昌"]["2"] is False:
                    for i in range(3):
                        # 6 左上角一个僵尸
                        is_get = self.DotaCheckMoveAttack(16, 637, 600, 500)
                        if is_get == 1:
                            self.data["高昌"]["2"] = True
                            gu_bi_num=self.OcrGuBiNum()
                            self.log.info("古币 %s" % gu_bi_num)
                            if gu_bi_num>200:
                                self.data["高昌"]["4"] = True
                                self.data["高昌"]["5"] = True
                            break
                elif self.data["高昌"]["3"] is False:
                    for i in range(10):
                        is_get = self.DotaCheckMoveAttack(22, 638, 534, 445)
                        if is_get == 1:
                            self.dm.KeyPressChar("s")
                            is_get=self.AccessNPC(0,0,521,541)
                            if is_get==1:
                                self.dm.LeftClick(587,678,n=3)
                                self.data["高昌"]["3"] = True
                            break
                elif self.data["高昌"]["4"] is False:
                    for i in range(10):
                        # 6 7 中间 3个
                        is_get = self.DotaCheckMoveAttack(28, 638, 600, 460)
                        if is_get==1:
                            self.data["高昌"]["4"] =True
                            gu_bi_num = self.OcrGuBiNum()
                            self.log.info("古币 %s" % gu_bi_num)
                            if gu_bi_num > 200:
                                self.data["高昌"]["5"] = True
                            break
                elif self.data["高昌"]["5"] is False:
                    for i in range(10):
                        # 7 下面3个
                        is_get = self.DotaCheckMoveAttack(33, 646, 600, 500, step=1)
                        if is_get == 1:
                            self.data["高昌"]["5"] = True
                            break
                elif self.data["高昌"]["6"] is False:
                    gu_bi_num = self.OcrGuBiNum()
                    self.log.info("古币 %s" % gu_bi_num)
                    if gu_bi_num < 201:
                        self.data["高昌"]["5"] = False
                    else:
                        for i in range(10):
                            is_get = self.DotaCheckMoveAttack(35, 642, 593, 400, step=1)
                            if is_get == 1:
                                self.dm.KeyPressChar("s")
                                is_get = self.AccessNPC(0, 0, 665, 441)
                                if is_get == 1:
                                    self.dm.LeftClick(587, 678, n=3)
                                    self.data["高昌"]["6"] = True
                                break
                else:
                    self.modifyStage(second_stage=second_stage + 1)
            elif second_stage == 6:
                # 等待兑换完客昌丹和功法残页
                res = self.ExchangeMilitaryAchievements(5)
                if res ==1:
                    self.UseSkillBook(20)
                    if self.publicData["辅助"]["是否67"]:
                        self.modifyStage(second_stage=second_stage + 1)
                        self.data["当前任务"] = "6"
                    elif self.publicData["辅助"]["是否9"]:
                        self.modifyStage(second_stage=second_stage + 2)
                        self.data["当前任务"] = "9"
                    else:
                        self.modifyStage(second_stage=second_stage + 9)
            elif second_stage == 7:
                # 67
                self.JoinGaoChangCheck(1)
                if self.data["当前任务"] == "6":
                    res = self.DoSupTask6()
                    self.log.info(res)
                    if res ==1:
                        is_get = self.dm.SearchPngClick(992, 460, 1280, 650, r"书\挑战令6.bmp", 0.9, 1, 0.1, 2, 5, 5)
                        if is_get==1 and len(self.data["任务"]["6"]) != 0:
                            self.data["当前任务"] = "6boss"
                        elif len(self.data["任务"]["7"]) !=0:
                            self.data["当前任务"] = "7"
                        if self.CheckPublicWarehouse(r"书\7级藏宝图.bmp|书\仓库7级藏宝图.bmp") ==1:
                            self.data["任务"]["7"]=[]
                    else:
                        time.sleep(1)
                elif self.data["当前任务"] == "7":
                    res = self.DoSupTask7()
                    self.log.info(res)
                    if res == 1:
                        if self.CheckPublicWarehouse(r"书\6级藏宝图.bmp|书\仓库6级藏宝图.bmp") ==1:
                            self.data["任务"]["6"]=[]
                        if len(self.data["任务"]["6"]) != 0:
                            self.data["当前任务"] = "6"
                    else:
                        time.sleep(1)
                elif self.data["当前任务"] == "6boss":
                    res = self.DoSupTask6Boss()
                    self.log.info(res)
                    if res == 1:
                        if self.CheckPublicWarehouse(r"书\7级藏宝图.bmp|书\仓库7级藏宝图.bmp") ==1:
                            self.data["任务"]["7"]=[]
                        if len(self.data["任务"]["7"]) != 0:
                            self.data["当前任务"] = "7"
                        elif len(self.data["任务"]["6"]) != 0:
                            self.data["当前任务"] = "6"
                    else:
                        time.sleep(1)
                if len(self.data["任务"]["6"]) == 0 and len(self.data["任务"]["7"]) == 0  :
                    if self.publicData["辅助"]["是否9"]:
                        self.modifyStage(second_stage=second_stage + 1)
                        self.data["当前任务"] = "9"
                    else:
                        self.modifyStage(second_stage=second_stage + 2)
            elif second_stage == 8:
                if self.data["辅助抽宝石时间"] <60.0:
                    self.data["辅助抽宝石时间"] = time.time()
                if self.data["辅助兑换战功时间"] <60.0:
                    self.data["辅助兑换战功时间"] = time.time()
                self.JoinGaoChangCheck(1)
                self.log.info("开始 9")
                res = self.DoSupTask9()
                self.log.info("结束 9")
                self.log.info(res)
                if self.CheckPublicWarehouse(r"书\9级藏宝图.bmp|书\仓库9级藏宝图.bmp") == 1:
                    self.data["任务"]["7"] = []
                if len(self.data["任务"]["9"]) == 0 :
                    self.modifyStage(second_stage=second_stage + 1)
            else:
                self.modifyStage(main_stage="等待")
                self.BotSay()
                self.modifyStage(second_stage=99999)
        elif main_stage == "等待":
            self.Challenge_Archive()
            if self.publicData["辅助"]["是否抽宝石"]:
                self.SupDrawGem()
                self.SupExchangeMilitaryAchievements(8)
            else:
                self.SupExchangeMilitaryAchievements(6)
            self.dm.KeyPressChar("f1",num=2)
            if self.publicData["辅助"]["R紫"]:
                self.RGemPurple()
            if self.publicData["辅助"]["是否9"]:
                if self.publicData["是否回家过"] or self.publicData["是否回门派过"]:
                    self.data["是否在高昌"] = False
                if self.data["是否在高昌"] is False:
                    res = self.JoinGaoChang(1)
                    self.dm.KeyPressChar("f1", num=2)
                    is_get = self.dm.SearchPngClick(100, 20, 1100, 520, "主线\门派战功兑换.bmp", 0.8, 1, 0.3, 0, 0, 0)
                    if is_get == 1:
                        self.data["是否在高昌"] = False

                self.log.info("开始 9")
                res = self.DoSupTask9()
                self.log.info("结束 9")


            time.sleep(1)
        elif main_stage == "存档":
            second_stage = self.get_second_stage()
            self.log.info(second_stage)
            res = self.dm.SearchPngClick(111, 672, 129, 690, r"主线\1号位图标.bmp", 0.90, 1, 0, 0, 0, 0)
            self.log.info("龙进入情况%s" % res)
            if second_stage == "存档":
                for i in range(10):
                    res = self.dm.SearchPngClick(111, 672, 129, 690, r"主线\1号位图标.bmp", 0.90, 1, 0, 0, 0, 0)
                    self.log.info("龙进入情况%s" % res)
                    res=self.CheckMode()
                    self.log.info("当前模式: %s"%res)
                    self.publicData["基础配置"]["模式"]=res
                    if self.publicData["存档"]["是否打龙"] is False:
                        self.data["是否进入龙"] = True
                    if res=="":
                        continue
                    elif res=="侠客行":
                        self.data["是否进入龙"] = True
                        break
                    elif res == "异国志":
                        if self.publicData["存档"]["是否进扶桑"] is False:
                            self.data["是否进船坞扶桑"]=True
                        break
                    elif res == "华山之巅":
                        self.data["是否进入黄陵"] = True
                        break
                # 区别第一次进入
                if self.publicData["辅助"]["智能合宝石"]:
                    self.log.info("存档合宝石")
                    self.SynthesisGemByLvs([3, 4, 5, 6, 7], handIn=True)
                else:
                    is_get = self.dm.SearchPngClick(1024, 650, 1122, 680, "存档\宝石\一键合成.bmp|存档\宝石\一键合成2.bmp",
                                                    0.9, 3, 0.1, 1, 2, 2)
                    is_get = self.dm.SearchPngClick(1024, 650, 1122, 680, "存档\宝石\一键合成.bmp|存档\宝石\一键合成2.bmp",
                                                    0.9, 3, 0.1, 1, 2, 2)
                    is_get = self.dm.SearchPngClick(1024, 650, 1122, 680, "存档\宝石\一键合成.bmp|存档\宝石\一键合成2.bmp",
                                                0.9, 3, 0.1, 1, 2, 2)
                    self.HandInGem()

                self.publicData["系统数据"]["防守成功数"] += 1
                if self.publicData["存档"]["是否刷黄陵"] is False:
                    self.data["是否进入黄陵"] = True
                if self.publicData["存档"]["是否论剑"] is False:
                    self.data["是否进入论剑"] = True
                self.modifyStage(second_stage="")
            if not self.data["是否黄陵中"]:
                self.log.info("不在黄陵中使用背包所有物品")
                if self.publicData["基础配置"]["模式"] in ["普通", "y", "侠客行", "华山之巅"]:
                    self.UseAllBossSaveData()
                else:
                    self.UseAllItems()
            self.log.info( self.data["是否论剑中"])
            if self.data["是否论剑中"] is False and self.data["是否黄陵中"] is False :
                self.F3Save()
                # 辅助不需要看大哥 顺序不定
                if self.data["是否商人购买"] is False:
                    self.log.info("商人购买")
                    self.BuyArchiveMerchant()
                    self.data["是否商人购买"]=True

                if self.data["是否进入龙"] == 0:
                    self.log.info("检查进龙")
                    res = self.dm.SearchPngClick(111, 672, 129, 690, r"主线\1号位图标.bmp", 0.90, 5, 0.3, 0, 0, 0)
                    self.log.info("龙进入情况%s" % res)
                    if res ==1:
                        res=self.JoinDragon()
                        if res==1:
                            self.data["是否进入龙"] = 1
                if self.data["是否进船坞扶桑"] is False:
                    self.log.info("检查进船坞扶桑")
                    res=self.JoinDockAndFusang()
                    if res ==1:
                        self.data["是否进船坞扶桑"] = True

                if self.data["是否进入论剑"] is False and self.data["是否进船坞扶桑"] is True and self.publicData["存档"]["是否论剑"] is True:
                    self.log.info("检查进论剑")
                    res = self.CompetitionOnHuashan()
                    self.log.info(res)
                    if res == 0:
                        self.data["是否进入论剑"] = True
                        self.data["是否论剑中"]=True
                    elif res == 1:
                        self.data["是否论剑中"] = False

                if self.data["是否进入黄陵"] is False and self.data["是否进船坞扶桑"] is True:
                    res = self.ImperialMausoleumEnter()
                    if res == 1:
                        self.data["是否进入黄陵"] = True
                        self.data["是否黄陵中"] = True
                        self.data["是否论剑中"] = False
            elif self.data["是否论剑中"] and self.publicData["存档"]["是否论剑"] is True:
                self.log.info("检查大哥是否开启黄陵")
                res = self.ImperialMausoleumEnter()
                if res == 1:
                    self.data["是否进入黄陵"] = True
                    self.data["是否黄陵中"] = True
                    self.data["是否论剑中"] = False
                res = self.CompetitionOnHuashan()
                if res == 0:
                    self.data["是否进入论剑"] = True
                    self.data["是否论剑中"] = True
                elif res == 1:
                    self.data["是否论剑中"] = False
            elif self.data["是否黄陵中"]:
                self.ImperialMausoleuChose()
                self.log.error("检查是否在黄陵")

                is_get = self.CheckPersonPosition(93, 649, 0.8, 1, 1, 100, 59, 620, 480)
                if is_get == 1:
                    self.publicData["人物不在黄陵次数"] = 0
                else:
                    self.log.info("人物不在黄陵次数%s"%self.publicData["人物不在黄陵次数"])
                    self.publicData["人物不在黄陵次数"] += 1
                if self.publicData["人物不在黄陵次数"] > 8:
                    self.modifyStage(main_stage="存档等待")

        elif main_stage == "存档等待":
            start_time = time.time()
            for i in range(60):
                self.log.info(i)

                if self.publicData["基础配置"]["模式"] in ["普通", "y", "侠客行", "华山之巅"]:
                    self.UseAllBossSaveData()
                    self.UseAllBossSaveData()
                else:
                    self.UseAllItems()
                    self.UseAllItems()
                if self.publicData["每日"]["排行榜奖励"]:
                    self.GetRankingReward()
                self.log.info(self.publicData["辅助"]["提前退出"])
                if self.publicData["辅助"]["提前退出"]:
                    break
                self.log.info(self.publicData["大哥不在线次数"])
                if self.publicData["大哥不在线次数"] >1:
                    break
                time.sleep(1)
                end_time=time.time()
                is_get = self.dm.SearchPngClick(500, 520, 1080, 580, "存档\失败退出游戏覆盖.bmp", 0.8, 1, 0, 0, 0, 0)
                if is_get == 1:
                    self.dm.LeftClick(583, 421, 2)
                    time.sleep(1)
                is_get = self.dm.SearchPngClick(500, 520, 1080, 700,"存档\成功退出游戏.bmp", 0.8, 1, 0, 0, 0, 0)
                if is_get == 1:
                    self.modifyStage(main_stage="退出游戏")
                    break
                if (end_time - start_time) > 60.0:
                    break
            self.modifyStage(main_stage="退出游戏")
        elif main_stage == "退出游戏":

            self.log.info("本局游戏结束")
            self.dm.UnBindWindow()
            time.sleep(1)

            return 1
        else:
            self.log_stage()
    def BotSay(self):
        msg = "I am a robot, if I affect you, please change your password and kick me out."
        msg = ""
        self.dm.KeyPressChar("enter")
        for i in msg:
            if i == " ":
                self.dm.KeyPressChar("space", step=0.01)
            else:
                self.dm.KeyPressChar(i, step=0.01)
        self.dm.KeyPressChar("enter")


    def DoSupTask6(self):
        check_path = self.dm.GetPicAbsPath("|".join(self.data["任务"]["6全"]))
        self.log.info("执行辅助6")
        res = self.DotaCheckMoveAttack(21, 641, 730, 390)
        if res == 1:
            self.log.info("移动到目标6")
            for i in range(10):
                self.PickUp(0, 0, 700, 362)
                self.dm.KeyPressChar("f1",num=2)
                self.log.info("查找是否有书")
                is_get=self.dm.SearchPngClick(992, 460, 1280, 650, check_path, 0.9, 5, 0.1,  0, 0, 0)
                if is_get==1:
                    for i in range(3):
                        self.MoveMouseSafe()
                        time.sleep(0.3)
                        self.log.info(self.data["任务"]["6"])
                        if len(self.data["任务"]["6"])!=0:
                            taskPath = self.dm.GetPicAbsPath("|".join(self.data["任务"]["6"]))
                        else:
                            return 1
                        res, x, y = self.dm.FindPicEx(996, 460, 1279, 646, taskPath, "000000", 0.9)
                        if res != -1:
                            # 取放逻辑需加优化 校验
                            is_get = self.PutIntoPublicWarehouse(self.data["任务"]["6"][res])
                            del self.data["任务"]["6"][res]
                        else:
                            break
                    self.log.info("开始提交6多余商品书")
                    if self.publicData["辅助"]["是否提交所有上品书"]:
                        for i in range(3):
                            check_path2 = self.dm.GetPicAbsPath("|".join(self.data["任务"]["6上"]))
                            res, x, y = self.dm.FindPicEx(996, 460, 1279, 646, check_path2, "000000", 0.9)
                            if res != -1:
                                # 取放逻辑需加优化 校验
                                is_get = self.PutIntoPublicWarehouse(self.data["任务"]["6上"][res])
                            else:
                                break
                    self.SellingCheats(check_path)
                    return 1
        return  0
    def DoSupTask6Boss(self):
        if   r"书\6红三光奇功.bmp" in self.data["任务"]["6"] :
            self.log.info("有存档令且没有红书 打boss6")
            flag=False
            for i in range(3):
                res = self.DotaCheckMoveAttack(15, 641, 700, 362,step=1,n=30)
                if res ==1:
                    flag=True
                    break
            if flag is False:
                self.log.info("未移动到 6 boss 退出")

            for i in range(10):
                self.PickUp(15, 641, 900, 400)
                self.dm.KeyPressChar("f1", num=2)
                is_get = self.dm.SearchPngClick(992, 460, 1280, 650,r"书\6红三光奇功.bmp", 0.9, 10, 0.1, 0, 0, 0)
                if is_get==1:
                    for i in range(3):
                        self.MoveMouseSafe()
                        time.sleep(0.5)
                        self.log.info(self.data["任务"]["6"])
                        if len(self.data["任务"]["6"])!=0:
                            taskPath = self.dm.GetPicAbsPath("|".join(self.data["任务"]["6"]))
                        else:
                            return 1
                        res, x, y = self.dm.FindPicEx(996, 460, 1279, 646, taskPath, "000000", 0.9)
                        if res != -1:
                            # 取放逻辑需加优化 校验
                            is_get = self.PutIntoPublicWarehouse(self.data["任务"]["6"][res])
                            del self.data["任务"]["6"][res]
                        else:
                            break
                    return 1
                else:
                    time.sleep(5)
        else:
            return 1
    def DoSupTask7(self):
        check_path = self.dm.GetPicAbsPath("|".join(self.data["任务"]["7全"]))
        self.log.info([35, 642, 706, 360])
        res = self.DotaCheckMoveAttack(35, 642, 706, 320)
        if res == 1:
            self.log.info("移动到目标7")
            for i in range(10):
                self.PickUp(0, 0, 700, 262)
                self.dm.KeyPressChar("a")
                self.dm.KeyPressChar("f1",num=2)
                self.log.info("查找是否有书")

                if self.publicData["辅助"]["智能合宝石"]:
                    self.log.info("7合宝石")
                    self.SynthesisGemByLvs([3, 4, 5], handIn=True)
                else:
                    is_get = self.dm.SearchPngClick(1024, 650, 1122, 680,
                                                    "存档\宝石\一键合成.bmp|存档\宝石\一键合成2.bmp",
                                                    0.9, 3, 0.1, 1, 2, 2)
                    self.HandInGem()

                is_get = self.dm.SearchPngClick(992, 460, 1280, 650, r"书\挑战令7.bmp", 0.9, 1, 0.1, 2, 5, 5)
                is_get=self.dm.SearchPngClick(992, 460, 1280, 650, check_path, 0.9, 5, 0.1,  0, 0, 0)
                if is_get==1:
                    for i in range(3):
                        self.MoveMouseSafe()
                        self.log.info(self.data["任务"]["7"])
                        if len(self.data["任务"]["7"])!=0:
                            taskPath = self.dm.GetPicAbsPath("|".join(self.data["任务"]["7"]))
                        else:
                            return 1
                        res, x, y = self.dm.FindPicEx(996, 460, 1279, 646, taskPath, "000000", 0.9)
                        if res != -1:
                            # 取放逻辑需加优化 校验
                            is_get = self.PutIntoPublicWarehouse(self.data["任务"]["7"][res])
                            del self.data["任务"]["7"][res]
                        else:
                            break
                    self.log.info("开始提交7多余商品书")
                    if self.publicData["辅助"]["是否提交所有上品书"]:
                        for i in range(3):
                            check_path2 = self.dm.GetPicAbsPath("|".join(self.data["任务"]["7上"]))
                            res, x, y = self.dm.FindPicEx(996, 460, 1279, 646, check_path2, "000000", 0.9)
                            if res != -1:
                                # 取放逻辑需加优化 校验
                                is_get = self.PutIntoPublicWarehouse(self.data["任务"]["7上"][res])
                            else:
                                break
                    self.SellingCheats(check_path)
                    return 1
        return  0
    def DoSupTask9(self):
        check_path = self.dm.GetPicAbsPath("|".join(self.data["任务"]["9全"]))
        self.log.info([45, 650, 500, 373])
        res = self.DotaCheckMoveAttack(45, 650, 540, 373)

        self.log.info(res)
        if res == 1:
            self.log.info("移动到目标9")
            if self.data["是否开启9上"] is False:
                gu_bi_num=self.OcrGuBiNum()
                res=self.AccessNPC(0,0,594,188)
                if res==1:
                    self.dm.LeftClick(587, 678, n=3)
                    if gu_bi_num > 1000:
                        self.data["是否开启9上"] = True
            for i in range(1):
                if self.publicData["是否回家过"] or self.publicData["是否回门派过"]:
                    break
                self.PickUp(0, 0, 600, 362)
                self.dm.KeyPressChar("f1",num=2)
                self.log.info("查找是否有9书")
                is_get = self.dm.SearchPngClick(992, 460, 1280, 650, r"书\挑战令9.bmp", 0.9, 3, 0.1, 2, 5, 5)
                self.HandInGem()
                if self.publicData["辅助"]["智能合宝石"]:
                    self.log.info("9合宝石")
                    self.SynthesisGemByLvs([3, 4, 5, 6, 7], handIn=True)
                else:
                    is_get = self.dm.SearchPngClick(1024, 650, 1122, 680,
                                                    "存档\宝石\一键合成.bmp|存档\宝石\一键合成2.bmp", 0.9, 3, 0.1, 1, 2,
                                                    2)
                    self.HandInGem()
                is_get=self.dm.SearchPngClick(992, 460, 1280, 650, check_path, 0.9, 5, 0.1,  0, 0, 0)
                if is_get==1:
                    for i in range(2):
                        self.MoveMouseSafe()
                        time.sleep(0.5)
                        self.log.info(self.data["任务"]["9"])
                        if len(self.data["任务"]["9"])!=0:
                            taskPath = self.dm.GetPicAbsPath("|".join(self.data["任务"]["9"]))
                        else:
                            break
                        res, x, y = self.dm.FindPicEx(996, 460, 1279, 660, taskPath, "000000", 0.9)
                        if res != -1:
                            # 取放逻辑需加优化 校验
                            is_get = self.PutIntoPublicWarehouse(self.data["任务"]["9"][res])
                            del self.data["任务"]["9"][res]
                        else:
                            break
                    self.log.info("开始提交9多余商品书")
                    if self.publicData["辅助"]["是否提交所有上品书"]:
                        for i in range(3):
                            check_path2 = self.dm.GetPicAbsPath("|".join(self.data["任务"]["9上"]))
                            res, x, y = self.dm.FindPicEx(996, 460, 1279, 646, check_path2, "000000", 0.9)
                            if res != -1:
                                # 取放逻辑需加优化 校验
                                is_get = self.PutIntoPublicWarehouse(self.data["任务"]["9上"][res])
                            else:
                                break
                    self.SellingCheats(check_path)
                    return 1
        return  0

    def F3Save(self):
        for i in range(2):
            self.GoHome(25,step=0.1)
            time.sleep(1)
            # 检查是否在家
            is_in = self.CheckPersonPosition(68, 660, 0.8, 1, 1, 100, 100, 980, 620)
            if is_in == 1:
                is_in = self.CheckPersonPosition(68, 660, 0.8, 1, 1, 100, 100, 980, 620)
                if is_in == 1:
                    return 1

        return 0


    def UnlockArms(self):
        self.log.info("开始解锁武器")
        is_get=self.AccessNPC(62, 663,581, 222)
        path = "存档\大旗秘藏.bmp|存档\见禅知意.bmp|存档\浪迹天涯.bmp" # todo
        path = "存档\大旗秘藏.bmp|存档\见禅知意.bmp"
        if is_get==1:
            is_get = self.dm.WaitPngDisappear(447, 619, 925, 714, path, 0.9, 5, 0.102, 2, 10, 10,is_wait=1)
            if is_get==0:
                return 1
        return 0

    # 选择w技能
    def ChooseWKill(self,name1,name2):
        self.log.info("刷w功法")
        self.GoSect()
        path =r"功法\%s.bmp|功法\%s.bmp"%(name1,name2)
        for i in range(10):
            self.dm.LeftClick(485, 634, 1)
            time.sleep(0.2)
            is_get = self.dm.SearchPngClick(456, 629, 495, 666, path, 0.8, 1, 0.1, 0, 0, 0)
            if is_get==1:
                return 1
        return 0

    # 拿洗髓经
    def GetMarrowCleansingSutra(self):
        for i in range(5):
            is_get = self.dm.SearchPngClick( 405, 330, 885, 475,"主线\洗髓经_极品.bmp|主线\洗髓经_极品2.bmp|主线\洗髓经_普通.bmp|主线\洗髓经_普通2.bmp|主线\洗髓经_垃圾.bmp|主线\洗髓经_垃圾2.bmp", 0.9, 20, 0.1, 0, 0, 0)
            if is_get==1:
                for i in range(1):
                    is_get = self.dm.SearchPngClick( 405, 330, 885, 475,"主线\洗髓经_极品.bmp|主线\洗髓经_极品2.bmp", 0.9, 1, 0, 1, 5, 5)
                    if is_get==1:
                        break
                    is_get = self.dm.SearchPngClick( 405, 330, 885, 475,"主线\洗髓经_普通.bmp|主线\洗髓经_普通2.bmp", 0.9, 1, 0, 1, 5, 5)
                    if is_get == 1:
                        break
                    self.dm.LeftClick(550, 400, 1)
                    break

                time.sleep(0.5)
                is_get = self.dm.SearchPngClick(530, 300, 800, 430, "主线\获取洗髓经.bmp", 0.9, 10, 0.5, 1, 20, 90,is_wait=1)
                if is_get==1:
                    break



